/* tslib 单点触摸程序 */
#include <stdio.h>
#include <stdlib.h>
#include <tslib.h>

int main(int argc, char *argv[])
{
    struct tsdev *ts = NULL;
    struct ts_sample sample;
    int pressure = 0; /* 保存上一次的按压力,初始为0,表示松开 */

    /* 打开并配置触摸屏设备 */
    ts = ts_setup(NULL, 0);
    if (NULL == ts) {
        fprintf(stderr, "ts_setup failed\n");
        exit(EXIT_FAILURE);
    }

    /* 读取数据 */
    for (;;) {
        if (0 > ts_read(ts, &sample, 1)) {
            fprintf(stderr, "ts_read failed\n");
            ts_close(ts);
            exit(EXIT_FAILURE);
        }

        if (sample.pressure) { /* 若按压力>0 */
            if (pressure) { /* 若上一次的按压力>0 */
                printf("移动(%d, %d)\n", sample.x, sample.y);
            } else {
                printf("按下(%d, %d)\n", sample.x, sample.y);
            }
        } else {
            printf("松开\n"); /* 打印坐标 */
        }
        pressure = sample.pressure;
    }

    ts_close(ts);
    exit(EXIT_SUCCESS);
}